package org.heima.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;


import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        /*WebView view = (WebView) findViewById(R.id.wv);
        view.getSettings().setJavaScriptEnabled(true);
        view.setWebViewClient(new WebViewClient());
        view.loadUrl("https://www.hao123.com");*/
        //================================================================

        try {
            URL url = new URL("http://www.hao123.com");
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            //http:的请求方法
            connection.setRequestMethod("GET");//get:表示希望从服务器那里获取数据,//post:表示提交数据
            connection.setConnectTimeout(5000);//设置连接超时
            connection.setReadTimeout(3000);//设置读取超时的毫秒数
            InputStream is = connection.getInputStream();//获取到服务器返回的输入流
            connection.disconnect();//关闭HTTP连接
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
